<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['basic']=$basic;
$return['banner']=$basic['hdps'];
//print_r($basic['hdps']);exit;
if($_RQ['op']=='main'){
	/*******main*******/
	//首页轮播图
	//首页分类
	/*
	$setting=uni_setting('pay');
	$wechat_cert=$setting['wechat_cert'];
	$wechat_key=$setting['wechat_key'];
	if(!$wechat_cert){
		exi('请在站点支付参数设置中设置CRET证书文件内容');
	}
	if(!$wechat_key){
		exi('请在站点支付参数设置中设置KEY密钥文件内容');
	}
	//以公众号uniacid生成文件夹
	$dir = iconv("UTF-8", "GBK", ROOT_D.'/addons/jy_zhongchou/cert/'.$_SESSION['uniacid']);
	if (!file_exists($dir)){
		mkdir ($dir,0777,true);
		//  echo '创建文件夹成功';
	} else {
		//  echo '需创建的文件夹已经存在';
	}
	$data=array();
	//上传cert证书
	if($wechat_cert&&$wechat_key){
			
		$certfilename=pdo_getcolumn('core_attachment',array('attachment'=>$wechat_cert),'title');
		$keyfilename=pdo_getcolumn('core_attachment',array('attachment'=>$wechat_key),'title');
			
		$certfile_data=cfc('files')->source_read($wechat_cert);
		$keyfile_data=cfc('files')->source_read($wechat_key);
			
		file_put_contents(ROOT_D.'/addons/jy_zhongchou/cert/'.$_SESSION['uniacid'].'/'.$certfilename.'.pem',$certfile_data);
		file_put_contents(ROOT_D.'/addons/jy_zhongchou/cert/'.$_SESSION['uniacid'].'/'.$keyfilename.'.pem',$keyfile_data);
			
		exi('认证文件上传成功','error');
		}
		*/
		
	$groups=pdo_getall('jy_zhongchou_classify',array('uniacid'=>$_SESSION['uniacid'],'is_show'=>'1'),'','paixu asc');
	if($classify){
		foreach($classify as &$item){
	
		}
	}
	if($groups){
		foreach($groups as &$r){
			$r['pnum']=pdo_count('jy_zhongchou_project',array('uniacid'=>$_SESSION['uniacid'],'cid'=>$r['id'],'is_shenhe'=>1,'status'=>0));
		}
	}
	$return['sharedata']=array(
		'title'=>$basic['share_title'],
		'desc'=>$basic['share_desc'],
		'link'=>custom_url('jy_zhongchou/index/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	$return['groups']=$groups;
	$plisthot=pdo_getall('jy_zhongchou_project',array('uniacid'=>$_SESSION['uniacid'],'is_shenhe'=>'1','status'=>'0','is_p'=>1),'','jtimes desc');
	if($plisthot){
		foreach($plisthot as &$item){
			$classify=pdo_get('jy_zhongchou_classify',array('id'=>$item['cid'],'uniacid'=>$_SESSION['uniacid']));
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['classify']=$classify;
			$item['shouchishenfenz']=json_decode($item['shouchishenfenz'],true);
			$item['hospitalz']=json_decode($item['hospitalz'],true);
			$item['buchong']=json_decode($item['buchong'],true);
			$item['progress']=100*$item['getmoney']/$item['goalmoney'];
		}
	}
	$return['plisthot']=$plisthot;
	$return['params']=array();
	set_html('title',$basic['title']?'首页-'.$basic['title']:'首页-微众筹');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>0,'is_shenhe'=>1);
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
		}else{
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['title'];
		}
	}
	//按捐款笔数排序项目
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_zhongchou_project',$params,array($pindex,$psize),$total,$fields,'','jtimes desc, id desc');
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$classify=pdo_get('jy_zhongchou_classify',array('id'=>$item['cid'],'uniacid'=>$_SESSION['uniacid']));
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['classify']=$classify;
			$item['shouchishenfenz']=json_decode($item['shouchishenfenz'],true);
			$item['hospitalz']=json_decode($item['hospitalz'],true);
			$item['buchong']=json_decode($item['buchong'],true);
			$item['progress']=100*$item['getmoney']/$item['goalmoney'];
		}
	}
	$return['list']=$list;
	$return['params']['page'] =$pindex;
	exi($return);
}